/**
 * Created by Administrator on 2016/8/11.
 */
define(["require",'config/appregister',"business/Companyinfor/service/htttp",
	"business/services/components","business/services/filter",
	"date","jquery","business/Companyinfor/directive/date2",
	"business/services/personCenterComp",
	"business/services/detailNavComp",
	"business/Companyinfor/directive/date3","business/workSkill/directive/startLevel"],function(require,app,httpServices){
	app.controller('comIndexCtrl',function($scope,$timeout,$http,$location,$state,$stateParams,auth){
		/*"business/services/regionService"*/
		auth.isCompanyLogin();
		auth.isLogin()
		companyInfo();
		/*路由跳转*/
		var param = $stateParams;
        $scope.bgColor = 0;
       
        var local = $location.$$path.split('/');
		
        function whichPage(){
        	switch(local[2]){
        		case 'sIndexCtrl':
        			$scope.bgColor = 0;
        			break;
        		case 'evaceCtrl':
        			$scope.bgColor = 1;
        			break;
        		case 'workPosCtrl':
        			$scope.bgColor = 2;
        			break;
    			case 'resource':
	    			$scope.bgColor = 3;
	    			break;
        		case 'friendCtrl':
        			$scope.bgColor = 4;
        			break;
        		case 'accountCtrl':
        			$scope.bgColor = 5;
        			break;
        		case 'comPanyBlogCtrl':
        			$scope.bgColor = 3;
	    		
        	}
        	 if( $scope.bgColor == 0){
        	$state.go("comIndexCtrl.sIndexCtrl");
        }
        }
        whichPage();
        $scope.signAcc=function(state){
        	if(!state){
				return
			}
			$state.go(state);
        	$scope.bgColor = 5;
        	
        }
		$scope.signAcc2=function(state){
			if(!state){
				return
			}
			$state.go(state);
			$scope.bgColor = 2;

		}
		$scope.showWork=1;
		$scope.signAcc3=function(state){
			if(!state){
				return
			}
			$state.go(state);
			$scope.bgColor = 2;
			$scope.showWork=2

		}
		$scope.signAcc4=function(state){
			if(!state){
				return
			}
			$state.go(state);
			$scope.bgColor = 2;
			$scope.showWork=3

		}
		$scope.singacc=function(state){
			if(!state){
				return
			}
			$state.go(state);
			$scope.bgColor = 3;

		}
		$scope.ResourceTab=1;
		$scope.linkvideo=function(state){
			if(!state){
				return
			}
			$state.go(state);
			$scope.bgColor = 3;
			$scope.ResourceTab=1;
		}

		$scope.linkBlog=function(state){
			if(!state){
				return
			}
			$state.go(state);
			$scope.bgColor = 3;
			$scope.ResourceTab=2;
			var req ={
                    type:"GET",
                    uri:"getList",
                    data:{
                        type:1,
                        pageNo: $scope.listParams.pageNo,
                        pageSize:$scope.listParams.pageSize,
                        all:"false"
                    }
                };
                httpServices.getBlog(req).success(function(response){
                    $scope.$apply(function(){
                    /*	console.log(JSON.stringify(response))*/
                        $scope.CompanyBlogCon= response.data.list;
                        $scope.totalItem=response.data.Pagination.totalCount;
                        getListModel();
                    })
                });
		}
		/*默认显示1的课程列表*/
		$scope.listParams = {
			currentTcId: "",
			download: false,
			time: false,
			pageNo: 1,
			pageSize:10,
			all: false,
			typeId: "",
			scId: "",
			dcId: "",
			keyWord:"",
			//dcName scName 用于加入缓存 在详情中显示面包树导航
			dcName:"",
			scName:""
		};
		$scope.tabCon = [
			{title:"主页",state:"comIndexCtrl.sIndexCtrl"},
			{title:"点评管理",state:"comIndexCtrl.evaceCtrl"},
			{title:"招聘管理",state:"comIndexCtrl.workPosCtrl"},
			{title:"资源管理",state:"comIndexCtrl.resource"},
			{title:"好友管理",state:"comIndexCtrl.friendCtrl"},
			{title:"账户管理",state:"comIndexCtrl.accountCtrl"},

		];
        function getBase2Info(){
            var req ={
                type:"GET",
                uri:"getBaseUeserInfo",
                data:{}
            };
            httpServices.getuserHttpService(req).success(function(result){
                $scope.$apply(function(){
                    $scope.coinValue = result.data.coinValue;
                })
            });

        }
        getBase2Info();
		//   $state.go("prosonMine.myUpload");
		$scope.currentItem = [];
		$scope.changeView = function(item,index){
		$scope.bgColor=index;
			$scope.currentItem = [];
			$scope.currentItem[index] = true;
			if(typeof item.state=="string" &&item.state!=""){
				$state.go(item.state);
			}
		};
		$scope.goTo = function(state){
			if(!state){
				return
			}
			$state.go(state);
		};

		/*字体八个颜色*/
		$scope.content = [
			{color:"#fe0000"},
			{color:"#fea100"},
			{color:"#f7f036"},
			{color:"#71cf0d"},
			{color:"#7edad9"},
			{color:"#83a6ef"},
			{color:"#f736da"},
			{color:"#fca5a5"}
		]
		//企业信息
		function companyInfo(){
		var req ={
			 type:"GET",
			 uri:"getBaseInfoByUser",
			 data:{}
		 };
			 httpServices.homePageHttpService(req).success(function(result){
			 $scope.$apply(function(){
				 if(result.data == null){
					 $state.go('indexCtrl');
				 }
				$scope.companyInfo = result.data;
				 $scope.compayId = result.data.companyId;

				 if(result.data.commentCount== "0"){
				 	$scope.evaSc=0
				 }else{
				 	$scope.evaSc = Math.ceil(result.data.totalScore/result.data.commentCount)
				 }
				
			 })
			 });
			
			
		}

		//企业主页
		//企业招聘
		function companyZp(){
			var req ={
			 type:"GET",
			 uri:"getRecruit",
			 data:{}
			 };
			 httpServices.homePageHttpService(req).success(function(response){
			 $scope.$apply(function(){
			 	/*console.log(JSON.stringify(response))*/
					$scope.companyZp = response.data;
			 })
			 });
			
		}
		companyZp();
		//企业资源
		function homeResource(){
			var req ={
			 type:"GET",
			 uri:"getResource",
			 data:{}
			 };
			 httpServices.homePageHttpService(req).success(function(response){
			 $scope.$apply(function(){
			 $scope.homeResource = response.data;
			 })
			 });
		}
		homeResource();
		//公司概况
		function getBasicFacts(){
			var req ={
			 type:"GET",
			 uri:"getBasicFacts",
			 data:{}
			 };
			 httpServices.homePageHttpService(req).success(function(response){
			 $scope.$apply(function(){
			 	$scope.basicFacts = response.data;
			 })
			 });
		}
		getBasicFacts();


	})
});

